package com.example.medical.controller.admin;

import com.example.medical.entity.dto.*;
import com.example.medical.service.AffairsService;
import com.example.medical.utils.common.enums.Code;
import com.example.medical.utils.common.result.Result;
import com.example.medical.utils.config.BaseContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/affairs")
public class AdminAffairsController {

    @Autowired
    private AffairsService affairsService;

    @PostMapping("/get_affairs_IB")
    public Result AdminGetAffairsIBList(@RequestBody GetAffairsListActionDto dto){
        return affairsService.GetAffairsActionList(dto);
    }

    @PostMapping("/get_affairs_OB")
    public Result AdminGetAffairsOBList(@RequestBody GetAffairsListActionDto dto){
        return affairsService.GetAffairsActionList(dto);
    }

    @PostMapping("/get_affairs_shift")
    public Result AdminGetAffairsShiftList(@RequestBody GetAffairsListDto dto){
        return affairsService.GetAffairsList(dto);
    }

    @PostMapping("/get_affairs_report_losses")
    public Result AdminGetAffairsReportLossesList(@RequestBody GetAffairsListDto dto){
        return affairsService.GetAffairsList(dto);
    }

    @PostMapping("/get_affairs_check")
    public Result AdminGetAffairsCheckList(@RequestBody GetAffairsListDto dto){
        return affairsService.GetAffairsList(dto);
    }

    @PostMapping("/get_affairs_repair")
    public Result AdminGetAffairsRepairList(@RequestBody GetAffairsListDto dto){
        return affairsService.GetAffairsList(dto);
    }

    @PostMapping("/get_affairs_buy")
    public Result AdminAffairsBuyList(@RequestBody GetAffairsListDto dto){
        return affairsService.GetAffairsList(dto);
    }

    @GetMapping("/get_affairs_detail")
    public Result AdminGetAffairsDetail(@RequestParam("id")Integer id){
        if (BaseContext.getCurrentId()==null) {
            return Result.errorResult(Code.NEED_LOGIN);
        }
        return Result.okResult(affairsService.getById(id));
    }

    @GetMapping("/remove_affairs_arr")
    public Result AdminRemoveAffairsArr(@RequestParam("ids")String[] ids,@RequestParam("memo")String memo){
        return affairsService.RemoveAffairsArr(ids,memo);
    }

    @GetMapping("/remove_affairs")
    public Result AdminRemoveAffairs(@RequestParam("id")Integer id){
        if (BaseContext.getCurrentId()==null) {
            return Result.errorResult(Code.NEED_LOGIN);
        }
        boolean checkRemove = affairsService.removeById(id);
        if (!checkRemove) {
            return Result.errorResult(Code.SERVER_ERROR);
        }
        return Result.okResult(Code.SUCCESS);
    }

    @PostMapping("save_affairs")
    public Result AdminSaveAffairs(@RequestBody AdminSaveAffairsDto dto){
        return affairsService.AdminSaveAffairs(dto);
    }

//    @GetMapping("/update_get_affairs")
//    public Result AdminUpdateGetAffairs(@RequestParam("id")Long id){
//        if (BaseContext.getCurrentId()==null) {
//            return Result.errorResult(Code.NEED_LOGIN);
//        }
//        return Result.okResult(affairsService.getById(id));
//    }
//
//    @PostMapping("/update_affairs")
//    public Result AdminUpdateAffairs(@RequestBody AdminUpdateAffairsDto dto){
//        return affairsService.AdminUpdateAffairs(dto);
//    }

//    @GetMapping("/OB_true")
//    public Result AdminOBTrue(@RequestParam("id")Long id){
//        return affairsService.AdminOBTrue(id);
//    }
//    @GetMapping("/IB_true")
//    public Result AdminIBTrue(@RequestParam("id")Long id){
//        return affairsService.AdminIBTrue(id);
//    }
//
//    @GetMapping("/buy_true")
//    public Result AdminBuyTrue(@RequestParam("id")Long id){
//        return affairsService.AdminBuyTrue(id);
//    }
//
//    @GetMapping("/repair_true")
//    public Result AdminRepairTrue(@RequestParam("id")Long id){
//        return affairsService.AdminRepaiTrue(id);
//    }

}
